import * as mine from "../../api/mine";
import validate from "../../utils/validate";
var appInst =  getApp();

Page({
    data: {
        form:{
            mobile:"",
            identifyNo:"",
            userName:"",
            userNo:"",
            nickName:""
        },
        realnameStatus:""
    },
    onLoad(){

        mine.get_user_info()
            .then((res)=>{
                this.setData({
                    ['form.userName']:res.userName,
                    ['form.mobile']:res.mobile,
                    ['form.identifyNo']:res.identifyNo,
                    ['form.userNo']:res.userNo,
                    ['form.nickName']:res.nickName,
                    realnameStatus:res.realnameStatus
                });
                wx.setNavigationBarTitle({
                    title: res.realnameStatus == 'N'?'我的信息':'我的信息'
                });
            })
    },
    handle_login_out(){
        mine.logout()
            .then(()=>{
                wx.removeStorageSync("openid");
                wx.removeStorageSync("session_key");
                appInst.globalData.pageCanLoad = true;
                wx.navigateBack({
                    delta: 1
                });
            })
    },
    changeNickName(e){
        let name = e.detail.value;
        if(name.length === 0) return;
        mine.modifyNickName({
            nickName:name
        })
            .then(()=>{
                this.setData({
                    ['form.nickName']: name
                })
            })
    }
})
